package com.hbq.codedemopersion.common.controller;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.DatagramSocket;
import java.net.InetSocketAddress;
import java.net.DatagramPacket;


public class Send_Client {

    public static void main(String[] args) throws Exception {
        DatagramSocket socket = new DatagramSocket();
        while (true) {
            //直接从控制台中读取数据
            BufferedReader data = new BufferedReader(new InputStreamReader(System.in));
            String datas = data.readLine();
            //将数据转换为可以传输的字节
            byte[] send_data = datas.getBytes();
            DatagramPacket packet = new DatagramPacket(send_data, 0, send_data.length, new InetSocketAddress("127.0.0.1", 888));
            socket.send(packet);
            //这里时设置他们怎么结束，可以自行展开
            if (datas.equals("bye")) {
                break;
            }
        }
        socket.close();
    }
}